home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Asymetrix Multimedia Toolbook 4.0 (CBT Edition)
/
Asymetric Multimedia Toolbook 4.0 (CBT Edition).iso
/
ctb40mt.z
/
PARADOX.ATS
< prev
next >
Wrap
Text File
|
1995-11-13
|
21KB
|
694 lines
SCRIPT "Link to Paradox"
BEHAVIOR "Link all the functions in the Asymetrix library TB40PDX.DLL. This library 'wraps' the Paradox Engine."
CATEGORY Paradox
{
to handle linkPX
linkDLL sysToolBookDirectory & "tb40PDX.DLL"
INT addPXKey(STRING,STRING,INT) --PXKeyAdd()
INT addPXPassword(STRING) --PXPswAdd()
INT addPXTable(STRING,STRING) --PXTblAdd()
INT appendPXRecord(STRING) --PXRecAppend()
INT clonePXBlob(STRING,STRING) --PXBlobClone()
INT closePXBitmapWindow(WORD)
INT closePXBlob(INT,INT) --PXBlobClose()
INT closePXTable(STRING) --PXTblClose()
INT copyPXTable(STRING,STRING) --PXTblCopy()
INT createPXTable(STRING,STRING,STRING) --PXTblCreate()
INT decryptPXTable(STRING) --PXTblDecrypt()
INT deletePXPassword(STRING) --PXPswDel()
INT deletePXRecord(STRING) --PXRecDelete()
INT deletePXTable(STRING) --PXTblDelete()
INT doesPXTableExist(STRING) --PXTblExist()
INT dropPXBlob(STRING,STRING) --PXBlobDrop()
INT dropPXKey(STRING,STRING,WORD) --PXKeyDrop()
INT emptyPXField(STRING,STRING)
INT emptyPXRecord(STRING) --PXRecBufEmpty()
INT emptyPXTable(STRING) --PXTblEmpty()
INT encryptPXTable(STRING,STRING) --PXTblEncrypt()
INT exitPX() --PXExit()
INT freePXGraphicBlob(WORD)
INT freePXGraphicBlobPalette(WORD)
INT firstPXRecord(STRING) --PXRecFirst()
LONG getPXBitmapSize(WORD)
LONG getPXBlob(INT,DWORD,LONG) --PXBlobGet()
LONG getPXBlobQuick(STRING,STRING,INT) --PXBlobQuickGet()
LONG getPXBlobSize(INT) --PXBlobGetSize()
STRING getPXErrorString(INT) --return error string
INT getPXFieldCount(STRING) --PXRecNFlds()
STRING getPXFieldNames(STRING)
STRING getPXFieldType(STRING,STRING) --PXFldType()
STRING getPXFieldValue(STRING,STRING)
LONG getPXFileSize(STRING)
LONG getPXGraphicBlob(INT)
LONG getPXGraphicBlobPalette(INT)
INT getPXKeyFieldCount(STRING) --PXKeyNFlds()
INT getPXMaxFiles()
INT getPXMaxLocks()
INT getPXMaxTables()
INT getPXSwapSizeFromINI()
INT getPXMaxTablesFromINI()
INT getPXMaxFilesFromINI()
INT getPXMaxLocksFromINI()
STRING getPXMemoBlob(INT)
STRING getPXNetErrorUser() --PXNetErrUser()
STRING getPXNetUserName() --PXNetUserName()
LONG getPXRaw(STRING,INT) --PXRawGet()
INT getPXRawDataSize(STRING)
LONG getPXRecordCount(STRING) --PXTblNRecs()
LONG getPXRecordNumber(STRING) --PXRecNum()
STRING getPXSortOrder()
INT getPXSwapSize()
STRING getPXUserInfo()
INT gotoPXNetRecordLock(STRING,INT) --PXNetRecGotoLock()
INT gotoPXRecord(STRING,LONG) --PXRecGoto()
INT initializePX(STRING) --PXWinInit()
INT insertPXRecord(STRING) --PXRecInsert()
INT isPXNetRecordLocked(STRING) --PXNetRecLocked()
INT isPXNetTableChanged(STRING) --PXNetTblChanged()
INT isPXTableProtected(STRING) --PXTblProtected()
INT lastPXRecord(STRING) --PXRecLast()
INT lockPXNetFile(STRING,INT) --PXNetFileLock()
LONG lockPXNetRecord(STRING) --PXNetRecLock()
INT lockPXNetTable(STRING,INT) --PXNetTblLock()
LONG mapPXKey(STRING,STRING,STRING,INT) --PXKeyMap()
INT nextPXRecord(STRING) --PXRecNext()
LONG openPXBitmapWindow(WORD,WORD,WORD,STRING,INT,STRING)
LONG openPXBlobRead(STRING,STRING) --PXBlobOpenRead()
LONG openPXBlobWrite(STRING,STRING,LONG,INT)--PXBlobOpenWrite()
INT openPXTable(STRING,STRING,INT,INT) --PXTblOpen()
INT packPXTable(STRING)
INT previousPXRecord(STRING) --PXRecPrev()
STRING queryPXKey(STRING) --PXKeyQuery()
INT refreshPXNetTable(STRING) --PXNetTblRefresh()
INT renamePXTable(STRING,STRING) --PXTblRename()
INT savePX() --PXSave()
INT searchPXField(STRING,STRING,WORD,INT)
INT searchPXKey(STRING,INT,STRING,INT) --PXSrchKey()
INT setPXBitmapWindowInfo(WORD,WORD,WORD,INT,STRING)
INT setPXBlob(INT,DWORD,LONG,WORD) --PXBlobPut()
INT setPXBlobFromFile(INT,DWORD,DWORD,DWORD,STRING)--PXBlobPut()
INT setPXFieldValue(STRING,STRING,STRING) --PXPutAlpha(), PXPutDate(),
--PXPutDouble(), PXPutLong(), PXPutShort()
INT setPXGraphicBlob(INT,WORD,WORD) --PXBlobPut()
INT setPXGraphicBlobFromFile(INT,STRING) --PXBlobPut()
INT setPXINIMaxFiles(INT) --PXSetDefaults()
INT setPXINIMaxLocks(INT) --PXSetDefaults()
INT setPXINIMaxTables(INT) --PXSetDefaults()
INT setPXMemoBlob(INT,STRING) --PXBlobPut()
INT setPXRaw(STRING,INT,INT) --PXRawPut()
INT setPXSortOrder(STRING)
INT setPXINISwapSize(INT)
INT setPXTableCreateMode(INT) --PXTblCreateMode()
INT setPXTableMaxSize(INT) --PXTblMaxSize()
INT setPXUserInfo(STRING)
INT unlockPXNetFile(STRING,INT) --PXNetFileUnlock()
INT unlockPXNetRecord(STRING,INT) --PXNetRecUnlock()
INT unlockPXNetTable(STRING,INT) --PXNetTblUnlock()
INT updatePXRecord(STRING) --PXRecUpdate()
INT upgradePXTable(STRING) --PXTblUpgrade()
LONG writePXBlobToFile(INT,STRING,INT) --PXBlobPut()
LONG writePXGraphicBlobToFile(INT,STRING,INT)--PXBlobPut()
end linkDLL
clear sysError
end linkPX
}
SCRIPT "Initialize the Paradox engine"
BEHAVIOR "Initializes the Paradox Engine for Windows "
CATEGORY Paradox
ARG pxAlias is "myDBName" help "Can be set to an arbitrary name"
{
-- all "to get" handlers return the error code, calling handler must deal at that level
-- do this first
to get initPX $$pxAlias
return initializePX($$pxAlias)
end initPX
}
SCRIPT "Create a Paradox database"
BEHAVIOR "Creates a new database"
CATEGORY Paradox
ARG tName is "myDatabase" help "Name of new database without extension."
{
-- Pass fNameList and fTypeSize from the calling handler.
-- fNameList will be a list of the names of the fields in the database
-- fTypeSize will be a corresponding list of the types and sizes of those fields
-- E.g. fNameList = "LastName,FirstName,Address";fTypeSize = "A15,A15,M10"
to get createTable $$tName,fNameList,fTypeSize
if itemCount(fNameList) <> itemCount(fTypeSize)
request "Name list and type list for this database do not match. Please correct and try again."
return -1
end if
return createPXTable($$tName, fNameList, fTypeSize)
end createTable
}
SCRIPT "Open a Paradox table"
BEHAVIOR "Opens a table with an index "
CATEGORY Paradox
ARG tBufType oneof "0,1" is "0" help "Work with buffer (0) or write straight to disk (1). Type 0 is prefered for performance."
ARG tIndex is "0"
ARG tName is "myDatabase" help "The name the db file, without extension."
ARG tAlias is "myTable"
{
to get openTable $$tAlias,$$tName
-- arbitrary alias.
-- the name the db file, without extension.
-- index id, 0 = PRIMARY.
-- work with buffer (0) or write straight to disk (1). Type 0 is prefered for performance
return openPXTable($$tAlias,$$tName,$$tIndex,$$tBufType)
end openTable
}
SCRIPT "Close a Paradox table"
BEHAVIOR "Closes a table "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to get closeTable $$tAlias
-- takes an alias to a table
return closePXTable($$tAlias)
end closeTable
}
SCRIPT "Get the total number of records"
BEHAVIOR "Returns the toal number of records in a table "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to get totalRecords $$tAlias
return getPXRecordCount($$tAlias)
end
}
SCRIPT "Get the current record number"
BEHAVIOR "Returns the record number of the current record "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to get currentRecord $$tAlias
return getPXRecordNumber($$tAlias)
end currentRecord
}
SCRIPT "Navigate to a record"
BEHAVIOR "Intelligently sets the current record "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to set CurrentRecord $$tAlias to value
clear sysError
conditions
when value is "next"
get nextPXRecord($$tAlias)
when value is "last"
get lastPXRecord($$tAlias)
when value is "previous"
get previousPXRecord($$tAlias)
when value is "first"
get firstPXRecord($$tAlias)
else
if isType(REAL, value) and (value > 0)
get gotoPXRecord($$tAlias,value)
else
request "Bad value trying to set current record."
break
end
end conditions
conditions
when it = -101 -- start of table
get firstPXRecord($$tAlias)
when it = -102 -- end of table
get lastPXRecord($$tAlias)
end conditions
if it < 0
request getPXErrorString(it)
end if
end currentRecord
}
SCRIPT "Get the value of a Paradox field"
BEHAVIOR "Gets the value for a field in the current record "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to get fieldValue $$tAlias,fieldName
DBfieldType = getPXFieldType($$tAlias,fieldName)
clear SysError
retVal = -1 -- set return value to error, reset if value found
conditions
-- memo "BLOB" (Binary Large OBject)
when first char of DBfieldType = "M"
hPrivateBlob = openPXBlobRead($$tAlias, fieldName)
if hPrivateBlob < 0
retVal = hPrivateBlob
else
retVal = getPXMemoBlob(hPrivateBlob)
get closePXBlob(hPrivateBlob, 0)
end if
-- graphics BLOB
when first Char of DBfieldType = "G"
hPrivateBlob = openPXBlobRead($$tAlias, fieldName)
if hPrivateBlob < 0
retVal = hPrivateBlob
else
-- returns two items,
-- handle to the bitmap and handle to the palette
retVal = getPXGraphicBlob(hPrivateBlob)
set item 2 of retVal to getPXGraphicBlobPalette(hPrivateBlob)
get closePXBlob(hPrivateBlob, 0)
end
-- BLOB (the "B" stands for binary)
when first Char of DBfieldType = "B"
hPrivateBlob = openPXBlobRead($$tAlias, fieldName)
if hPrivateBlob < 0
send PXError hPrivateBlob
else
retVal = getPXBlob(hPrivateBlob, getBlobSize(hPrivateBlob), 0)
get closePXBlob(hPrivateBlob, 0)
end
-- formatted text
when first Char of DBfieldType = "F"
-- debug
sysError = "This field type not supported: Formatted text"
-- OLE BLOB
when first Char of DBfieldType = "O"
sysError = "This field type not supported: OLE Blob"
-- all others
else
get getPXFieldValue($$tAlias,fieldName)
retVal = it
end
return retVal
end
-- assuming a text field, called like this:
-- to handle myUpdate
-- get fieldValue(my name)
-- if it < 0
-- if it = -1
-- request sysError
-- else
-- request getPXErrorString(it)
-- end if
-- else
-- set my text to it
-- end if
-- end myUpdate
}
SCRIPT "Set the value of a field"
BEHAVIOR "Determines the data type for a field, then sets the value of that field "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to set fieldValue fieldName to value
DBfieldType = getPXFieldType($$tAlias,fieldName)
clear sysError
pxErr = 1
conditions
-- memo BLOB
when first char of DBfieldType = "M"
BLOBSize = charCount(value)
hPrivateBlob = openPXBlobWrite($$tAlias, fieldName, BLOBSize, 0)
if hPrivateBlob < 0
pxErr = hPrivateBlob
else
pxErr = setPXMemoBlob(hPrivateBlob, value)
get closePXBlob(hPrivateBlob, 1)
end if
-- graphics BLOB from file
when first char of DBfieldType = "G"
BLOBSize = getPXFileSize(value) + 8 -- for header
hPrivateBlob = openPXBlobWrite(DBTable of self, fieldName, BLOBSize, 0)
if hPrivateBlob < 0
pxErr = hPrivateBlob
else
pxErr = setPXGraphicBlobFromFile(hPrivateBlob, value)
get closePXBlob(hPrivateBlob, 1)
end if
-- binary BLOBs
when first char of DBfieldType = "B"
linkDLL "kernel"
WORD globalAlloc(WORD,DWORD)
POINTER globalLock(WORD)
WORD globalUnlock(WORD)
WORD globalFree(WORD)
end linkDLL
BLOBSize = charCount(value)
hPrivateBlob = openPXBlobWrite($$tAlias, fieldName, BLOBSize, 0)
if hPrivateBlob < 0
pxErr = hPrivateBlob
-- how you deal with this next step depends a lot on what kind
-- of data you are using. For this example, we are assuming a "/0"
-- terminated string (normal Windows string). At the other extreme,
-- you could place the data in the buffer stepping a byte at a time through
-- value using "step" and "pointerByte". Your solution will likely
-- be somewhere in the middle.
else
-- 66 is the type of memory: initialized to zero, movable
hVal = globalAlloc(66,BLOBSize)
-- create a pointer
pVal = globalLock(hVal)
-- place the data into memory
get pointerString(0,pVal,value)
-- tell Paradox where to get the data
pxErr = setPXBlob(hPrivateBlob, BLOBSize, 0, pVal)
-- clean up
get closePXBlob(hPrivateBlob, 1)
get globalUnlock(hVal)
get globalFree(hVal)
end if
-- formatted memo BLOB
when first char of DBfieldType = "F"
sysError = "This field type not supported: Formatted text"
-- OLE BLOB
when first char of DBfieldType = "O"
sysError = "This field type not supported: OLE Blob"
-- all other
else
pxErr = setPXfieldvalue(DBTable of self,fieldName, value)
end conditions
if pxErr < 1
sysError = getPXErrorString(pxErr)
end if
end fieldValue
}
SCRIPT "Set BLOB from a file"
BEHAVIOR "Set an arbitrary binary large object using a file as the source "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to set BlobFromFile fieldName to fileName
BLOBSize = getPXFileSize(fileName)
-- "0" means new blob, not a local copy
hPrivateBlob = openPXBlobWrite($$tAlias, fieldName, BLOBSize, 0)
if hPrivateBlob < 0
pxErr = hPrivateBlob
else
-- "0, 0" are the respective offsets for the file and blob.
pxErr = setPXBlobFromFile(hPrivateBlob, BLOBSize, 0, 0, fileName)
get closePXBlob(hPrivateBlob, 1)
end if
if pxErr < 1
sysError = getPXErrorString(pxErr)
end if
end BlobFromFile
}
SCRIPT "Add a key"
BEHAVIOR "Add an index to a Paradox table"
CATEGORY Paradox
{
to get addKey appName,newAlias,fieldName,mode
-- for case-sensitive, single-field indexes
-- returns errorCode
get openPXTable(newAlias,appName,0,0) -- open new table indexed to primary
if it < 0 -- not likely
return it
end if
-- Mode for creating index
-- 0 Primary index (key)
-- 1 Secondary index (maintained only when open)
-- 2 Incremental Secondary index (maintained even if closed)
if mode = NULL
set mode to 2 -- safest
end if
get addPXKey(newAlias,fieldName,mode)
if it < 0
return it
end if
get closeTable(newAlias)
return it
end addKey
}
SCRIPT "Add a compound key"
BEHAVIOR "Add a case-insensitive or compound-field key (index)"
CATEGORY Paradox
{
to get addCompoundKey appName,newAlias,fieldList,mode,keyName
-- for case-insensitive or compound-field indexes
-- returns PX-assigned number for the index, or error code
get openPXTable(newAlias,appName,0,0)
if it < 0
return it
end if
-- 1 = case insensitive or compound
fieldNumber = mapPXKey(newAlias,fieldList,keyName,1)
if fieldNumber < 0
return fieldNumber
end if
if mode = NULL
set mode to 2 -- safest
end if
get addPXKey(newAlias,keyName,mode)
if it < 0
return it
end if
get closePXTable(newAlias)
if it < 0
return it
end if
return fieldNumber
-- now open the table from the calling handler
-- get openPXTable(newAlias, appName, fieldNumber, savemode)
end addCompoundKey
}
SCRIPT "Drop a Paradox key"
BEHAVIOR "Drop an key (index) for a particular field "
CATEGORY Paradox
{
to get dropKey alias,fieldName,appName,indexID
-- returns error code
-- table closed on this alias at return
get openPXTable(alias,appName,indexID,0)
if it < 0 -- impossible
return it
else
get dropPXKey(alias,fieldName,indexID) -- ref by name and indexID
if it < 0
retValue = it
get closePXTable(alias)
return retValue
else
get closePXTable(alias)
return it
end if
end if
end dropKey
}
SCRIPT "Open a tb40pdx.dll bitmap window"
BEHAVIOR "Open a bitmap window and display a graphic blob in it. "
CATEGORY Paradox
ARG hWndBitmap is "s_hWndBitmap"
ARG tFieldName is "Photo"
ARG tAlias is "myTable"
{
to get openBitmapWindow
system $$hWndBitmap
-- This will open a window and show the graphic blob in it
-- $$hWndBitmap is the handle to a window you're creating,
hPrivateBlob = openPXBlobRead("$$tAlias", "$$tFieldName")
if hPrivateBlob < 0
return hPrivateBlob
else
hBitmap = getPXGraphicBlob(hPrivateBlob)
hPalette = getPXGraphicBlobPalette(hPrivateBlob)
get closePXBlob(hPrivateBlob, 0)
end if
-- "2" = center the bitmap over the target
$$hWndBitmap = openPXBitmapWindowInfo(hBitmap, hPalette, 2, rgbFill of this page)
if $$hWndBitmap < 0
return getPXErrorString($$hWndBitmap)
end if
return "SUCCESS"
end openBitmapWindow
}
SCRIPT "Set Bitmap Info"
BEHAVIOR "In an already created window, set the bitmap and/or palette "
CATEGORY Paradox
ARG hWndBitmap is "s_hWndBitmap"
ARG tAlias is "myTable"
{
to set PXBitmapWindowInfo to BMPField
-- this will show the graphic blob in a window
-- hWndBitmap is a handle to a window you've already created,
-- possibly with openPXBitmapWindow()
system $$hWndBitmap
hPrivateBlob = openPXBlobRead($$tAlias, BMPField)
if hPrivateBlob < 0
request getPXErrorString(hPrivateBlob)
else
hBitmap = getPXGraphicBlob(hPrivateBlob)
hPalette = getPXGraphicBlobPalette(hPrivateBlob)
get closePXBlob(hPrivateBlob, 0)
-- "2" = center the bitmap over the target
pxErr = setPXBitmapWindowInfo($$hWndBitmap, hBitmap, hPalette, 2, rgbFill of this page)
if pxErr < 0
request getPXErrorString(pxErr)
end if
end if
end PXBitmapWindowInfo
}
SCRIPT "Update record"
BEHAVIOR "Updates the current record in a table "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to handle updateDB
get updatePXRecord($$tAlias)
if it < 0
request getPXErrorString(it)
end
end updateDB
}
SCRIPT "Update record to a table on the network"
BEHAVIOR "Updates the current record in a table that may be shared by other users "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to handle netUpdateDB
lockHandle = lockPXNetRecord($$tAlias)
conditions
-- we've got the lock
when lockHandle >= 0
clear sysError
get updatePXRecord($$tAlias)
if it < 0
request getPXErrorString(it)
end if
-- already locked
when lockHandle = -9
request "The record is locked by another user"
-- disappeared
when lockHandle = -50
request "The record has been deleted by another user. Do you want to insert it?" with "OK" or "Cancel"
if it = "OK"
get emptyPXRecord($$tAlias) -- clear recordBuffer
-- you will probably want to modify this to work with your app,
-- but the idea is to fill the buffer with the values ToolBook
-- is currently displaying in its fields.
step i from 1 to objects of this page
set curOb to item i of objects of this page
if object of curOb contains "field" -- fields and recordfields
-- set recordBuffer to current info, name of field in db and tb are the same
set fieldValue(name of curOb) to text of curOb
end if
end step
get insertPXRecord($$tAlias) -- place current record buffer in db
end if
else
request getPXErrorString(it)
end conditions
get unlockPXNetRecord($$tAlias, lockHandle)
end netUpdateDB
}
SCRIPT "Insert an empty record"
BEHAVIOR "Inserts a record before the current record in a non-indexed table "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to get insertRecord
get emptyPXRecord($$tAlias)
if it < 0 -- should never happen
return it
end if
--Insert record before the current record in a non-indexed table
ask "Enter record number to insert before."
if it <> null
get gotoPXRecord($$tAlias, it)
end
return insertPXRecord($$tAlias)
end insertRecord
}
SCRIPT "Append an empty record"
BEHAVIOR "Places a new record at the end of the table "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to get appendRecord
get emptyPXRecord($$tAlias)
if it < 0 -- should never happen
return it
end if
-- returns an empty record.
return appendPXRecord($$tAlias)
end
}
SCRIPT "Delete a Paradox record"
BEHAVIOR "Deletes the current record "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to get deleteRecord
return deletePXRecord($$tAlias)
end deleteRecord
}
SCRIPT "Get Paradox field names"
BEHAVIOR "Returns the names of all the fields in a table "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to get PXFieldNames
return getPXFieldNames($$tAlias)
end PXFieldNames
}
SCRIPT "Get the Paradox field type"
BEHAVIOR "Returns the field type and size for a field in a table "
CATEGORY Paradox
ARG tAlias is "myTable"
{
to get PXFieldType fieldName
return getPXFieldType($$tAlias,fieldName)
end PXFieldType
}
SCRIPT "Paradox error handler"
BEHAVIOR "Returns the error string for any Paradox error number "
CATEGORY Paradox
{
to handle PXError errVal
request getPXErrorString(errVal)
end PXError
}